<?php
// 本类由系统自动生成，仅供测试用途
class DyAction extends Action {

	
	//预设  para一般自身的所有以及扩展的zabojingua东西
	//聚合
    private $all=array(
    	'mdmk'=>'Dy',//NB
  		'ttl'=>'党员管理',
  		'jn'=>array('tb_dzb ON f_dy_dzbid=dzbid','tb_dw ON f_dzb_dwid=dwid','tb_leibie ON f_dy_leibieid=leibieid','tb_jieduan ON f_dy_jieduanid=jieduanid','tb_beizhu ON f_dy_beizhuid=beizhuid','tb_guanxibiandong ON f_dy_guanxibiandongid=guanxibiandongid'),//NB
      //自己的全部+f的显示的东西
  		'para'=>array('dyid'=>'dyID','f_dzb_dwid'=>'党委','dwnm'=>'党委','f_dy_dzbid'=>'党支部','dzbnm'=>'党支部','dynm'=>'姓名','f_dy_leibieid'=>'类别','leibienm'=>'类别','f_dy_jieduanid'=>'阶段','jieduannm'=>'阶段','f_dy_beizhuid'=>'备注','beizhunm'=>'备注','f_dy_guanxibiandongid'=>'组织关系变动','guanxibiandongnm'=>'组织关系变动'),//NB
  		//抛去不是zabojin的属性针对para
      'notself'=>array('dzbnm','dwnm','leibienm','jieduannm','beizhunm','guanxibiandongnm'),
       ##########modify 添加修改中不需要展示和理会的属性 针对para
      'no_update'=>array('dyid','dzbnm','dwnm','leibienm','jieduannm','beizhunm','guanxibiandongnm'),
      #####update的时候允许为空的值 针对zabojin刨掉不然显示的update字段后
      'allowempty'=>array(),

      'hide_fld'=>array('dyid','f_dy_dzbid','f_dzb_dwid','f_dy_leibieid','f_dy_jieduanid','f_dy_beizhuid','f_dy_guanxibiandongid'),//NB
      'hide_cdt'=>array('dyid','dzbnm','dwnm','leibienm','jieduannm','beizhunm','guanxibiandongnm'),//NB
  		
    //   'spccdtls'=>array('spccdt_0'=>array('dyid<>0','dyID不为0【废话只是测试】')),
  		// 'odrls'=>array('dynm'),
    //   'spccdt_dflt'=>array('spccdt_0'),
    //   'odr_dflt'=>array('dynm'=>'ASC'),

      'spccdtls'=>array(),//NB
      'odrls'=>array(),//NB
      'spccdt_dflt'=>array(),//NB
      'odr_dflt'=>array(),//NB
      //hide的fld必须有，他们虽然不显示但是必须选择，这样才能在第一次进入query的时候，隐藏属性可以被调用，特别是id和fid
  		'fld_dflt'=>array('dyid','f_dzb_dwid','dwnm','f_dy_dzbid','dzbnm','dynm','f_dy_leibieid','leibienm','f_dy_jieduanid','jieduannm','f_dy_beizhuid','beizhunm','f_dy_guanxibiandongid','guanxibiandongnm'),//NB
  		'cdt_dflt'=>array(),//NB
  		
  		'lmt_dflt'=>10,//NB
  		
  		'defaultls'=>1,//默认枚举//NB
  		##########view
  		'no_view'=>array('dyid','f_dy_dzbid','f_dzb_dwid','f_dy_leibieid','f_dy_jieduanid','f_dy_beizhuid','f_dy_guanxibiandongid'),
	   
      #########删除提醒
      'deleteconfirm'=>'确定要删除此条记录？',
      #####转义
      'transmean'=>array(),//NB
      #####默认值
      'dfltvalue'=>array(),
      
    	);

    //公版
    public function query(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');$dzb=D('Dzb');
    	$pb->query($this->all);
      
      //如果党委定下来需要进行筛选的
      if($_GET['f_dzb_dwid_nb_cdt']){
        $dwid=$_GET['f_dzb_dwid_nb_cdt'];
        $arr_dzbls=$dzb->getdzblsbydwid($dwid);$dzbls=$arr_dzbls['data'];
        $this->assign('f_dy_dzbid',$dzbls);
      }

      $this->display('query');
  
    }

    public function export(){
      header("Content-Type:text/html; charset=utf-8");
      $pb=D('PB');$dzb=D('Dzb');$xls=D('Xls');
      $arr_return=$pb->queryALL($this->all);$return=$arr_return['data'];

      $thls=$return['thls'];$mls=$return['mls'];
      
      $xls->export($thls,$mls,'党员数据');

    }
    
    //公版
    public function view(){
    	header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->view($this->all);
		  $this->display('Cmn:view');
    }
   
   	//公版
   	public function update(){
   		header("Content-Type:text/html; charset=utf-8");
    	$pb=D('PB');
    	$pb->update($this->all);

      if($_GET['f_dzb_dwid']){
        $dwid=$_GET['f_dzb_dwid'];
        $arr_dzbls=$dzb->getdzblsbydwid($dwid);$dzbls=$arr_dzbls['data'];
        $this->assign('f_dy_dzbid',$dzbls);
      }

		  $this->display('update');
   	}

   	//公版
   	public function doupdate(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');
   		$arr_pattern=$pb->doupdate($this->all);
   		$data['pattern']=$arr_pattern['pattern'];

   		$this->ajaxReturn($data,'json');
   	}

   	//公版
   	public function dodelete(){
   		header("Content-Type:text/html; charset=utf-8");
   		$pb=D('PB');
   		$pb->dodelete($this->all);
  		
   		$this->ajaxReturn($data,'json');
   	}

    public function dogetdzbls(){
      header("Content-Type:text/html; charset=utf-8");
      $dzb=D('Dzb');
      $dwid=$_GET['dwid'];
      $arr_dzbls=$dzb->getdzblsbydwid($dwid);$dzbls=$arr_dzbls['data'];
      $data['dzbls']=$dzbls;

      $this->ajaxReturn($data,'json');
    }


    public function dodaorudata(){
      header("Content-Type:text/html; charset=utf-8");
      $dw=D('Dw');$dzb=D('Dzb');$leibie=D('Leibie');$jieduan=D('Jieduan');$beizhu=D('Beizhu');$guanxibiandong=D('Guanxibiandong');$dy=D('Dy');
        
      //导入有几种情况可能出现问题
      //①其他的项目可能不正确
      //②党支部和党委的关系不正确
      //③数据已经有了
      //正确的可以直接导入不正确的需要指明哪里不正确了
      import('@.ORG.PHPExcel');
      //设定缓存模式为经gzip压缩后存入cache（PHPExcel导入导出及大量数据导入缓存方式的修改 ）
      $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;
      $cacheSettings = array();
      PHPExcel_Settings::setCacheStorageMethod($cacheMethod,$cacheSettings);
  
      $objPHPExcel = new PHPExcel();
      // $con = mysql_connect("localhost","root","123456");
      // mysql_select_db('bms');
      //读入上传文件
      $myfl=session('myfl');$myfl=str_replace('/'.C('PROJECT'),'.',$myfl);
      //$objPHPExcel = PHPExcel_IOFactory::load($_FILES["inputExcel"]["tmp_name"]);
      $objPHPExcel = PHPExcel_IOFactory::load($myfl);
       
      $currentSheet = $objPHPExcel->getSheet(0);// 当前页
      $row_num = $currentSheet->getHighestRow();// 当前页行数
      $col_max = $currentSheet->getHighestColumn(); // 当前页最大列号

      $dyls=array();
      for($i = 2; $i <= $row_num; $i++){
          
        $ads = 'A' . $i; // 单元格坐标address
        $xuhao = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value  
        $ads = 'B' . $i; // 单元格坐标address
        $dwnm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'C' . $i; // 单元格坐标address
        $dzbnm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'D' . $i; // 单元格坐标address
        $dynm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'E' . $i; // 单元格坐标address
        $leibienm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'F' . $i; // 单元格坐标address
        $jieduannm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'G' . $i; // 单元格坐标address
        $beizhunm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value
        $ads = 'H' . $i; // 单元格坐标address
        $guanxibiandongnm = trim($currentSheet->getCell($ads)->getFormattedValue());//cell_value

        if(!$dwnm&&!$dzbnm&&!$dynm&&!$leibienm&&!$jieduannm&&!$beizhunm&&!$guanxibiandongnm){continue;}
        
        $str_error='';
        $flag_dwanddzb=0;//只要党委党支部有一个不正常就是1
        
        
        if(!$dwnm){$str_error=stradd($str_error,'无党委名称','、');}else{
          $arr_dwo=$dw->getmobydwnm($dwnm);$dwo=$arr_dwo['data'];
          if(!$dwo){$str_error=stradd($str_error,'党委名称未找到','、');$flag_dwanddzb=1;}
        }
       
        if(!$dzbnm){$str_error=stradd($str_error,'无党支部名称','、');}else{
          $arr_dzbo=$dzb->getmobydzbnm($dzbnm);$dzbo=$arr_dzbo['data'];
          if(!$dzbo){$str_error=stradd($str_error,'党支部名称未找到','、');$flag_dwanddzb=1;}
        }

        if(!$dynm){$str_error=stradd($str_error,'无党员名称','、');}

        if(!$leibienm){$str_error=stradd($str_error,'无类别名称','、');}else{
          $arr_leibieo=$leibie->getmobyleibienm($leibienm);$leibieo=$arr_leibieo['data'];
          if(!$leibieo){$str_error=stradd($str_error,'类别名称未找到','、');}
        }
       
        if(!$jieduannm){$str_error=stradd($str_error,'无阶段名称','、');}else{
          $arr_jieduano=$jieduan->getmobyjieduannm($jieduannm);$jieduano=$arr_jieduano['data'];
          if(!$jieduano){$str_error=stradd($str_error,'阶段名称未找到','、');}
        }

        if(!$beizhunm){$str_error=stradd($str_error,'无备注名称','、');}else{
          $arr_beizhuo=$beizhu->getmobybeizhunm($beizhunm);$beizhuo=$arr_beizhuo['data'];
          if(!$beizhuo){$str_error=stradd($str_error,'备注名称未找到','、');}
        }

        if(!$guanxibiandongnm){$str_error=stradd($str_error,'无关系变动名称','、');}else{
          $arr_guanxibiandongo=$guanxibiandong->getmobyguanxibiandongnm($guanxibiandongnm);$guanxibiandongo=$arr_guanxibiandongo['data'];
          if(!$guanxibiandongo){$str_error=stradd($str_error,'关系变动名称未找到','、');}
        }
        
        if($flag_dwanddzb==0){
          //进行②党支部和党委的关系不正确判断
          $arr_dwo=$dw->getmo($dzbo['f_dzb_dwid']);$dwo=$arr_dwo['data'];
          if(!$dwo){$str_error=stradd($str_error,'党支部和党委对应关系不正确','、');}
        }

        if(!$str_error){
          //说明各项数据合法，可以用来判断是否有这个人
          $where=' AND f_dy_dzbid='.$dzbo['dzbid']." AND dynm='".$dynm."'".' AND f_dy_leibieid='.$leibieo['leibieid'].' AND f_dy_jieduanid='.$jieduano['jieduanid'].' AND f_dy_beizhuid='.$beizhuo['beizhuid'].' AND f_dy_guanxibiandongid='.$guanxibiandongo['guanxibiandongid'];
          $arr_dyo=$dy->getmobywhere($where);$dyo=$arr_dyo['data'];
          if($dyo){$str_error=stradd($str_error,'该党员已经在名单中了','、');}

        }

        if($str_error){
          $dyo=array('xuhao'=>$xuhao,'dwnm'=>$dwnm,'dzbnm'=>$dzbnm,'dynm'=>$dynm,'leibienm'=>$leibienm,'jieduannm'=>$jieduannm,'beizhunm'=>$beizhunm,'guanxibiandongnm'=>$guanxibiandongnm,'str_error'=>$str_error);
          array_push($dyls, $dyo);
        }else{
          $dt=array('f_dy_dzbid'=>$dzbo['dzbid'],'dynm'=>$dynm,'f_dy_leibieid'=>$leibieo['leibieid'],'f_dy_jieduanid'=>$jieduano['jieduanid'],'f_dy_beizhuid'=>$beizhuo['beizhuid'],'f_dy_guanxibiandongid'=>$guanxibiandongo['guanxibiandongid']);
          $dy->add($dt);
        }
            
      }

      $data['dyls']=$dyls;
        
      $this->ajaxReturn($data,'json');
    }

}